/*
 * CcValue.c
 *
 *  Created on: 2012/04/24
 *      Author: guanxiaoying
 */
#include "../coredef.h"
#include "../table/table.h"
#include "cc.h"


/********* INT ***********/
static VOID ccValueSetInt( PVALUEINFO pvalue, U8 result );
static VOID ccValueGetInt( AST index, PVALUEINFO pvalue );
static S4 ccValueCompareInt( PVALUEINFO pst1, PVALUEINFO pst2 );
static S4  ccValueInt2S4( PVALUEINFO value );
static VOID ccValueConvert2Int( PVALUEINFO value, AST type );
/********* UINT ***********/
static VOID ccValueSetUInt( PVALUEINFO pvalue, U8 result );
static VOID ccValueGetUInt( AST index, PVALUEINFO pvalue );
static S4 ccValueCompareUInt( PVALUEINFO pst1, PVALUEINFO pst2 );
static U4  ccValueUInt2U4( PVALUEINFO value );
/********* LONG ***********/
static VOID ccValueSetLong( PVALUEINFO pvalue, U8 result );
static VOID ccValueGetLong( AST index, PVALUEINFO pvalue );
static S4 ccValueCompareLong( PVALUEINFO pst1, PVALUEINFO pst2 );
static S4  ccValueLong2S4( PVALUEINFO value );
/********* LONG LONG ***********/;
static S4 ccValueCompareLongLong( PVALUEINFO pst1, PVALUEINFO pst2 );
static S8  ccValueLongLong2S8( PVALUEINFO value );
/********* ULONG ***********/
static VOID ccValueSetULong( PVALUEINFO pvalue, U8 result );
static VOID ccValueGetULong( AST index, PVALUEINFO pvalue );
static S4 ccValueCompareUlong( PVALUEINFO pst1, PVALUEINFO pst2 );
static U4  ccValueULong2U4( PVALUEINFO value );
static U8  ccValueULong2U8( PVALUEINFO value );
/********* U LONG LONG***********/
static VOID ccValueSetULongLong( PVALUEINFO pvalue, U8 result );
static VOID ccValueGetULongLong( AST index, PVALUEINFO pvalue );
static S4 ccValueCompareUlongLong( PVALUEINFO pst1, PVALUEINFO pst2 );
static U8  ccValueULongLong2U8( PVALUEINFO value );
/********* FLOAT ***********/
static VOID ccValueGetFloat( AST index, PVALUEINFO pvalue );
static VOID ccValueSetFloat( PVALUEINFO pvalue, DOUBLE result );
static S4 ccValueCompareFloat( PVALUEINFO pst1, PVALUEINFO pst2 );
static S2  ccValueFloat2S2( PVALUEINFO value );
static U2  ccValueFloat2U2( PVALUEINFO value );
static S4  ccValueFloat2S4( PVALUEINFO value );
static U4  ccValueFloat2U4( PVALUEINFO value );
static S8  ccValueFloat2S8( PVALUEINFO value );
static U8  ccValueFloat2U8( PVALUEINFO value );
static FLOAT  ccValueFloat2Float( PVALUEINFO value );
/********* DOUBLE ***********/
static VOID ccValueGetDouble( AST index, PVALUEINFO pvalue );
static VOID ccValueSetDouble( PVALUEINFO pvalue, DOUBLE result );
static S4 ccValueCompareDouble( PVALUEINFO pst1, PVALUEINFO pst2 );
static S2  ccValueDouble2S2( PVALUEINFO value );
static U2  ccValueDouble2U2( PVALUEINFO value );
static S4  ccValueDouble2S4( PVALUEINFO value );
static U4  ccValueDouble2U4( PVALUEINFO value );
static S8  ccValueDouble2S8( PVALUEINFO value );
static U8  ccValueDouble2U8( PVALUEINFO value );
static DOUBLE  ccValueDouble2Double( PVALUEINFO value );
/********* LDOUBLE ***********/
static VOID ccValueGetLDouble( AST index, PVALUEINFO pvalue );
static VOID ccValueSetLDouble( PVALUEINFO pvalue, DOUBLE result );
static S4 ccValueCompareLDouble( PVALUEINFO pst1, PVALUEINFO pst2 );
static S2  ccValueLDouble2S2( PVALUEINFO value );
static U2  ccValueLDouble2U2( PVALUEINFO value );
static S4  ccValueLDouble2S4( PVALUEINFO value );
static U4  ccValueLDouble2U4( PVALUEINFO value );
static S8  ccValueLDouble2S8( PVALUEINFO value );
static U8  ccValueLDouble2U8( PVALUEINFO value );
static LDOUBLE  ccValueLDouble2LDouble( PVALUEINFO value );
/********* INT ***********/
static VOID ccValueSetInt( PVALUEINFO pvalue, U8 result )
{
	if( IS16BIT ){
		// 16bit
		pvalue->unValue.sval = result;
	}else{
		// default 32 bit
		pvalue->unValue.lVal = result;
	}
}
static VOID ccValueGetInt( AST index, PVALUEINFO pvalue )
{
	if( IS16BIT ){
		// 16bit
		pvalue->unValue.sval = stValueInfoAccess.s2value.get( index );
	}else{
		// default 32 bit
		pvalue->unValue.lVal = stValueInfoAccess.s4value.get( index );
	}
}
static S4 ccValueCompareInt( PVALUEINFO pst1, PVALUEINFO pst2 )
{
	S4 result=0;
	if( IS16BIT ){
		if( pst1->unValue.sval < pst2->unValue.sval ){
			result = -1;
		}else if( pst1->unValue.sval > pst2->unValue.sval ){
			result = 1;
		}else{
			result = 0;
		}
	}else{
		if( pst1->unValue.lVal < pst2->unValue.lVal ){
			result = -1;
		}else if( pst1->unValue.lVal > pst2->unValue.lVal ){
			result = 1;
		}else{
			result = 0;
		}
	}
	return result;
}
static S4  ccValueInt2S4( PVALUEINFO value )
{
	S4 result;
	if( IS16BIT ){
		result = (S4)value->unValue.sval ;
	}else{
		result = (S4)value->unValue.lVal ;
	}
	return result;
}
static VOID ccValueConvert2Int( PVALUEINFO value, AST type )
{
	switch( ( value->astType)  ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		break;
	case TYPE_UNSIGNED_INT:
		if( IS16BIT ){
			value->unValue.sval = (S2)ccValueUInt2U4( value );
		}else{
			value->unValue.lVal = (S4)ccValueUInt2U4( value );
		}
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		if( IS16BIT ){
			value->unValue.sval = (S2)ccValueLong2S4( value );
		}
		break;
	case TYPE_UNSIGNED_LONG:
		if( IS16BIT ){
			value->unValue.sval = (S2)ccValueULong2U4( value );
		}else{
			value->unValue.lVal = (S4)ccValueULong2U4( value );
		}
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		if( IS16BIT ){
			value->unValue.sval = (S2)ccValueLongLong2S8( value );
		}else{
			value->unValue.lVal = (S4)ccValueLongLong2S8( value );
		}
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		if( IS16BIT ){
			value->unValue.sval = (S2)ccValueULongLong2U8( value );
		}else{
			value->unValue.lVal = (S4)ccValueULongLong2U8( value );
		}
		break;
	case TYPE_FLOAT:
		if( IS16BIT ){
			value->unValue.sval = ccValueFloat2S2( value );
		}else{
			value->unValue.lVal = ccValueFloat2S4( value );
		}
		break;
	case TYPE_DOUBLE:
		if( IS16BIT ){
			value->unValue.sval = ccValueDouble2S2( value );
		}else{
			value->unValue.lVal = ccValueDouble2S4( value );
		}
		break;
	case TYPE_LONG_DOUBLE:
		if( IS16BIT ){
			value->unValue.sval = ccValueLDouble2S2( value );
		}else{
			value->unValue.lVal = ccValueLDouble2S4( value );
		}
		break;
	}
	value->astType = type;
}
/********* UINT ***********/
static VOID ccValueSetUInt( PVALUEINFO pvalue, U8 result )
{
	if( IS16BIT  ){
		// 16bit
		pvalue->unValue.usval = result;
	}else{
		// default 32 bit
		pvalue->unValue.ulVal = result;
	}
}
static VOID ccValueGetUInt( AST index, PVALUEINFO pvalue )
{
	if( IS16BIT  ){
		// 16bit
		pvalue->unValue.usval = stValueInfoAccess.u2value.get( index );
	}else{
		// default 32 bit
		pvalue->unValue.ulVal = stValueInfoAccess.u4value.get( index );
	}
}
static S4 ccValueCompareUInt( PVALUEINFO pst1, PVALUEINFO pst2 )
{
	S4 result =0 ;
	if( IS16BIT ){
		if( pst1->unValue.usval < pst2->unValue.usval ){
			result = -1;
		}else if( pst1->unValue.usval > pst2->unValue.usval ){
			result = 1;
		}else{
			result = 0;
		}
	}else{
		if( pst1->unValue.ulVal < pst2->unValue.ulVal ){
			result = -1;
		}else if( pst1->unValue.ulVal > pst2->unValue.ulVal ){
			result = 1;
		}else{
			result = 0;
		}
	}
	return result;
}
static U4  ccValueUInt2U4( PVALUEINFO value )
{
	U4 result;
	if( IS16BIT ){
		result = (U4)value->unValue.usval ;
	}else{
		result = (U4)value->unValue.ulVal ;
	}
	return result;
}
static VOID ccValueConvert2UInt( PVALUEINFO value, AST type )
{
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		if( IS16BIT ){
			value->unValue.usval = (U2)ccValueInt2S4( value );
		}else{
			value->unValue.ulVal = (U4)ccValueInt2S4( value );
		}
		break;
	case TYPE_UNSIGNED_INT:
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		if( IS16BIT ){
			value->unValue.usval = (U2)ccValueLong2S4( value );
		}else{
			value->unValue.ulVal = (U4)ccValueLong2S4( value );
		}
		break;
	case TYPE_UNSIGNED_LONG:
		if( IS16BIT ){
			value->unValue.usval = (U2)ccValueULong2U4( value );
		}else{
			value->unValue.ulVal = (U4)ccValueULong2U4( value );
		}
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		if( IS16BIT ){
			value->unValue.usval = (U2)ccValueLongLong2S8( value );
		}else{
			value->unValue.ulVal = (U4)ccValueLongLong2S8( value );
		}
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		if( IS16BIT ){
			value->unValue.usval = (U2)ccValueULongLong2U8( value );
		}else{
			value->unValue.ulVal = (U4)ccValueULongLong2U8( value );
		}
		break;
	case TYPE_FLOAT:
		if( IS16BIT ){
			value->unValue.usval = ccValueFloat2U2( value );
		}else{
			value->unValue.ulVal = ccValueFloat2U4( value );
		}
		break;
	case TYPE_DOUBLE:
		if( IS16BIT ){
			value->unValue.usval = ccValueDouble2U2( value );
		}else{
			value->unValue.ulVal = ccValueDouble2U4( value );
		}
		break;
	case TYPE_LONG_DOUBLE:
		if( IS16BIT ){
			value->unValue.usval = ccValueLDouble2U2( value );
		}else{
			value->unValue.ulVal = ccValueLDouble2U4( value );
		}
		break;
	}
	value->astType = type;
}
/********* LONG ***********/
static VOID ccValueSetLong( PVALUEINFO pvalue, U8 result )
{
	pvalue->unValue.lVal = result;
}
static VOID ccValueGetLong( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.lVal = stValueInfoAccess.s4value.get( index );
}
static S4 ccValueCompareLong( PVALUEINFO pst1, PVALUEINFO pst2 )
{
	S4 result = 0;
	if( pst1->unValue.lVal < pst2->unValue.lVal ){
		result = -1;
	}else if( pst1->unValue.lVal > pst2->unValue.lVal ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static S4  ccValueLong2S4( PVALUEINFO value )
{
	return value->unValue.lVal;
}
static S8  ccValueLong2S8( PVALUEINFO value )
{
	return (S8)value->unValue.lVal;
}
static VOID ccValueConvert2Long( PVALUEINFO value, AST type )
{
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.lVal = ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.lVal = (S4)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.lVal = (S4)ccValueULong2U4( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.lVal = (S4)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.lVal = (S4)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		value->unValue.lVal = ccValueFloat2S4( value );
		break;
	case TYPE_DOUBLE:
		value->unValue.lVal = ccValueDouble2S4( value );
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.lVal = ccValueLDouble2S4( value );
		break;
	}
	value->astType = type;
}
/********* LONG LONG ***********/
static VOID ccValueSetLongLong( PVALUEINFO pvalue, U8 result )
{
	pvalue->unValue.llval = result;
}
static VOID ccValueGetLongLong( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.llval = stValueInfoAccess.s8value.get( index );
}
static S4 ccValueCompareLongLong( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.llval < pst2->unValue.llval ){
		result = -1;
	}else if( pst1->unValue.llval > pst2->unValue.llval ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static S8  ccValueLongLong2S8( PVALUEINFO value )
{
	return (S8)value->unValue.llval;
}
static VOID ccValueConvert2LongLong( PVALUEINFO value, AST type )
{
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.llval = (S8)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.llval = (S8)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.llval = (S8)ccValueLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.llval = (S8)ccValueULong2U8( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.llval = (S8)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		value->unValue.llval = ccValueFloat2S8( value );
		break;
	case TYPE_DOUBLE:
		value->unValue.llval = ccValueDouble2S8( value );
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.llval = ccValueLDouble2S8( value );
		break;
	}
	value->astType = type;
}
/********* ULONG ***********/
static VOID ccValueSetULong( PVALUEINFO pvalue, U8 result )
{
	pvalue->unValue.ulVal = result;
}
static VOID ccValueGetULong( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.ulVal = stValueInfoAccess.u4value.get( index );
}
static S4 ccValueCompareUlong( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.ulVal < pst2->unValue.ulVal ){
		result = -1;
	}else if( pst1->unValue.ulVal > pst2->unValue.ulVal ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static U4  ccValueULong2U4( PVALUEINFO value )
{
	return (U4)value->unValue.ulVal;
}
static U8  ccValueULong2U8( PVALUEINFO value )
{
	return (U8)value->unValue.ulVal;
}
static VOID ccValueConvert2ULong( PVALUEINFO value, AST type )
{
	switch(( value->astType )){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.ulVal = (U4)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.ulVal = (U4)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.ulVal = (U4)ccValueLong2S4( value );
		break;
	case TYPE_UNSIGNED_LONG:
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.ulVal = (U4)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.ulVal = (U4)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		value->unValue.ulVal = ccValueFloat2U4( value );
		break;
	case TYPE_DOUBLE:
		value->unValue.ulVal = ccValueDouble2U4( value );
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.ulVal = ccValueLDouble2U4( value );
		break;
	}
	value->astType = type;
}
/********* U LONG LONG***********/
static VOID ccValueSetULongLong( PVALUEINFO pvalue, U8 result )
{
	pvalue->unValue.ullval = result;
}
static VOID ccValueGetULongLong( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.ullval = stValueInfoAccess.u8value.get( index );
}
static S4 ccValueCompareUlongLong( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.ullval < pst2->unValue.ullval ){
		result = -1;
	}else if( pst1->unValue.ullval > pst2->unValue.ullval ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static U8  ccValueULongLong2U8( PVALUEINFO value )
{
	return (U8)value->unValue.ullval;
}
static VOID ccValueConvert2ULongLong( PVALUEINFO value, AST type )
{
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.ullval = (U8)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.ullval = (U8)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.ullval = (U8)ccValueLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.ullval = (U8)ccValueULong2U8( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.ullval = (U8)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		break;
	case TYPE_FLOAT:
		value->unValue.ullval = ccValueFloat2U8( value );
		break;
	case TYPE_DOUBLE:
		value->unValue.ullval = ccValueDouble2U8( value );
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.ullval = ccValueLDouble2U8( value );
		break;
	}
	value->astType = type;
}
/********* FLOAT ***********/
static VOID ccValueGetFloat( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.dbVal = (FLOAT)stValueInfoAccess.dvalue.get( index );
}
static VOID ccValueSetFloat( PVALUEINFO pvalue, DOUBLE result )
{
	pvalue->unValue.dbVal = (FLOAT)result;
}
static S4 ccValueCompareFloat( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.dbVal < pst2->unValue.dbVal ){
		result = -1;
	}else if( pst1->unValue.dbVal > pst2->unValue.dbVal ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static S2  ccValueFloat2S2( PVALUEINFO value )
{
	return (S2)value->unValue.dbVal;
}
static U2  ccValueFloat2U2( PVALUEINFO value )
{
	return (U2)value->unValue.dbVal;
}
static S4  ccValueFloat2S4( PVALUEINFO value )
{
	return (S4)value->unValue.dbVal;
}
static U4  ccValueFloat2U4( PVALUEINFO value )
{
	return (U4)value->unValue.dbVal;
}
static S8  ccValueFloat2S8( PVALUEINFO value )
{
	return (S8)value->unValue.dbVal;
}
static U8  ccValueFloat2U8( PVALUEINFO value )
{
	return (U8)value->unValue.dbVal;
}
static FLOAT  ccValueFloat2Float( PVALUEINFO value )
{
	return (FLOAT)value->unValue.dbVal;
}
static void ccValueConvert2Float( PVALUEINFO value, AST type ){
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.dbVal = (FLOAT)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.dbVal = (FLOAT)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.dbVal = (FLOAT)ccValueLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.dbVal = (FLOAT)ccValueULong2U8( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.dbVal = (FLOAT)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.dbVal = (FLOAT)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		break;
	case TYPE_DOUBLE:
		value->unValue.dbVal = (FLOAT)ccValueDouble2Double( value );
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.dbVal = (FLOAT)ccValueLDouble2LDouble( value );
		break;
	}
	value->astType = type;
}
/********* DOUBLE ***********/
static VOID ccValueGetDouble( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.dbVal = stValueInfoAccess.dvalue.get( index );
}
static VOID ccValueSetDouble( PVALUEINFO pvalue, DOUBLE result )
{
	pvalue->unValue.dbVal = result;
}
static S4 ccValueCompareDouble( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.dbVal < pst2->unValue.dbVal ){
		result = -1;
	}else if( pst1->unValue.dbVal > pst2->unValue.dbVal ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static S2  ccValueDouble2S2( PVALUEINFO value )
{
	return (S2)value->unValue.dbVal;
}
static U2  ccValueDouble2U2( PVALUEINFO value )
{
	return (U2)value->unValue.dbVal;
}
static S4  ccValueDouble2S4( PVALUEINFO value )
{
	return (S4)value->unValue.dbVal;
}
static U4  ccValueDouble2U4( PVALUEINFO value )
{
	return (U4)value->unValue.dbVal;
}
static S8  ccValueDouble2S8( PVALUEINFO value )
{
	return (S8)value->unValue.dbVal;
}
static U8  ccValueDouble2U8( PVALUEINFO value )
{
	return (U8)value->unValue.dbVal;
}
static DOUBLE  ccValueDouble2Double( PVALUEINFO value )
{
	return (DOUBLE)value->unValue.dbVal;
}
static void ccValueConvert2Double( PVALUEINFO value, AST type ){
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.dbVal = (DOUBLE)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.dbVal = (DOUBLE)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.dbVal = (DOUBLE)ccValueLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.dbVal = (DOUBLE)ccValueULong2U8( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.dbVal = (DOUBLE)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.dbVal = (DOUBLE)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		value->unValue.dbVal = (DOUBLE)ccValueFloat2Float( value );
		break;
	case TYPE_DOUBLE:
		break;
	case TYPE_LONG_DOUBLE:
		value->unValue.dbVal = (DOUBLE)ccValueLDouble2LDouble( value );
		break;
	}
	value->astType = type;
}
/********* LDOUBLE ***********/
static VOID ccValueGetLDouble( AST index, PVALUEINFO pvalue )
{
	pvalue->unValue.dbVal = (LDOUBLE)stValueInfoAccess.dvalue.get( index );
}
static VOID ccValueSetLDouble( PVALUEINFO pvalue, DOUBLE result )
{
	pvalue->unValue.dbVal = result;
}
static S4 ccValueCompareLDouble( PVALUEINFO pst1, PVALUEINFO pst2 ){
	S4 result;
	if( pst1->unValue.dbVal < pst2->unValue.dbVal ){
		result = -1;
	}else if( pst1->unValue.dbVal > pst2->unValue.dbVal ){
		result = 1;
	}else{
		result = 0;
	}
	return result;
}
static S2  ccValueLDouble2S2( PVALUEINFO value )
{
	return (S2)value->unValue.dbVal;
}
static U2  ccValueLDouble2U2( PVALUEINFO value )
{
	return (U2)value->unValue.dbVal;
}
static S4  ccValueLDouble2S4( PVALUEINFO value )
{
	return (S4)value->unValue.dbVal;
}
static U4  ccValueLDouble2U4( PVALUEINFO value )
{
	return (U4)value->unValue.dbVal;
}
static S8  ccValueLDouble2S8( PVALUEINFO value )
{
	return (S8)value->unValue.dbVal;
}
static U8  ccValueLDouble2U8( PVALUEINFO value )
{
	return (U8)value->unValue.dbVal;
}
static LDOUBLE  ccValueLDouble2LDouble( PVALUEINFO value )
{
	return (LDOUBLE)value->unValue.dbVal;
}
static void ccValueConvert2LDouble( PVALUEINFO value, AST type ){
	switch( (value->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		value->unValue.dbVal = (LDOUBLE)ccValueInt2S4( value );
		break;
	case TYPE_UNSIGNED_INT:
		value->unValue.dbVal = (LDOUBLE)ccValueUInt2U4( value );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		value->unValue.dbVal = (LDOUBLE)ccValueLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG:
		value->unValue.dbVal = (LDOUBLE)ccValueULong2U8( value );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		value->unValue.dbVal = (LDOUBLE)ccValueLongLong2S8( value );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		value->unValue.dbVal = (LDOUBLE)ccValueULongLong2U8( value );
		break;
	case TYPE_FLOAT:
		value->unValue.dbVal = (LDOUBLE)ccValueFloat2Float( value );
		break;
	case TYPE_DOUBLE:
		value->unValue.dbVal = (LDOUBLE)ccValueDouble2Double( value );
		break;
	case TYPE_LONG_DOUBLE:
		break;
	}
	value->astType = type;
}
#define PPTOKEN_2_CONTANT   /*  outline で分割用、実用なし  */
/******************** 前処理数処理 ***************************/
static S4 ccValueTryIntNumber(PSZ pszNumStr, S4 from, S4 to, S4 base, PVALUEINFO pstValue)
{
	U8 result= 0;
	U8 tempResult=0;
	S4 i= from;
	U4 digit=0;
    S4 nUTypeCount =0 ;
    S4 nLTypeCount =0;
    S4 nRet = COEXIT_SUCCESS;
	if (from == to) {
		return COEXIT_ERROR;
	}

	for (; i < to; i++)
	{
		switch( pszNumStr[i] ){
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			digit = pszNumStr[i] -'0';
			break;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
			digit = pszNumStr[i] - 'a' + 10;
			break;
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
			digit = pszNumStr[i] - 'A' + 10;
			break;
		default:
			digit = base + 1;
			break;
		}
		if( digit >= base ){
			break;
		}
		tempResult = result;
		result= result*base + digit;
		if( tempResult > result )
		{
			nRet = COEXIT_WARNING;
		}
	}
	for (; i < to; i++) {
		switch(pszNumStr[i]) {
		case 'u' : case 'U':
			nUTypeCount++;
			break;
		case 'l': case 'L':
			nLTypeCount++;
			break;
		default:
			i = to;
			nRet = COEXIT_ERROR;
			break;
		}
	}

	if( nUTypeCount == 1 && nLTypeCount == 2 ){
		pstValue->astType = ( TYPE_UNSIGNED_LONG_LONG);
		ccValueSetULongLong( pstValue, result );
	}else if( nUTypeCount == 1 && nLTypeCount == 1 ){
		pstValue->astType = ( TYPE_UNSIGNED_LONG);
		ccValueSetULong( pstValue, result );
	}else if( nUTypeCount == 1 && nLTypeCount == 0 ){
		pstValue->astType = ( TYPE_UNSIGNED_INT);
		ccValueSetUInt( pstValue, result );
	}else if( nUTypeCount == 0 &&  nLTypeCount == 2 ){
		pstValue->astType = ( TYPE_LONG_LONG);
		ccValueSetLongLong( pstValue, result );
	}else if( nUTypeCount == 0 &&  nLTypeCount == 1 ){
		pstValue->astType = ( TYPE_LONG);
		ccValueSetLong( pstValue, result );
	}else if( nUTypeCount == 0 &&  nLTypeCount == 0 ){
		pstValue->astType = ( TYPE_INT);
		ccValueSetInt( pstValue, result );
	}else{
		pstValue->astType = ( TYPE_INT);
		ccValueSetInt( pstValue, result );
		nRet = COEXIT_ERROR;
	}
	return nRet;
}
static S4 ccValueGetIntNumber(PSZ pszNumStr,PVALUEINFO pstValue )
{
    BOOL isBin = FALSE;
    BOOL isHex = FALSE;
    BOOL isOctal = FALSE;

    if (str_length(pszNumStr) > 1) {
    	if (pszNumStr[0] == '0') {
    		switch (pszNumStr[1]) {
    		case 'b':
    		case 'B':
    			isBin = TRUE;
    			break;
    		case 'x':
    		case 'X':
    			isHex = TRUE;
    			break;
    		case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
    			isOctal = TRUE;
    			break;
    		}
    	}
    }
    if (isBin) {
    	/*debug,13/1/29,S*/
    	return ccValueTryIntNumber( &pszNumStr[0], 2, strlen( pszNumStr ), 2, pstValue );
    	/*debug,13/1/29,E*/
    }
    if (isHex) {
    	/*debug,13/1/29,S*/
    	return ccValueTryIntNumber( &pszNumStr[0], 2, strlen( pszNumStr ), 16, pstValue );
    	/*debug,13/1/29,E*/
    }
    if (isOctal) {
    	/*debug,13/1/29,S*/
    	return ccValueTryIntNumber( &pszNumStr[0], 1, strlen( pszNumStr ), 8, pstValue );
    	/*debug,13/1/29,E*/
    }
	return ccValueTryIntNumber( &pszNumStr[0], 0, strlen( pszNumStr ), 10, pstValue );
}
static S4 ccValueSetFloatSuffix( S2 nFTypeCount, S2 nLTypeCount, DOUBLE result, PVALUEINFO pstValue ){
	if(  nFTypeCount == 1 && nLTypeCount == 1 ){
		pstValue->astType = (TYPE_LONG_DOUBLE);
		ccValueSetLDouble( pstValue, result );
	}else if( nFTypeCount == 1 && nLTypeCount == 0 ){
		pstValue->astType = (TYPE_FLOAT);
		ccValueSetFloat( pstValue, result );
	}else if( nFTypeCount == 0 && nLTypeCount == 0  ){
		pstValue->astType = (TYPE_DOUBLE);
		ccValueSetDouble( pstValue, result );
	}else{
		pstValue->astType = (TYPE_DOUBLE);
		ccValueSetDouble( pstValue, result );
		return COEXIT_ERROR;
	}
	return COEXIT_SUCCESS;
}
static S4 ccValueTryFloatNumber( PSZ pszNumStr, S4 from, S4 to, PVALUEINFO pstValue  )
{
	DOUBLE result_value= 0;
	DOUBLE result_franction=0;
	U4  u4_Exponent = 0;
	BOOL hasDot = FALSE;
	BOOL hasMinusSign = FALSE;
	S4 i= from;
	U4 digit=0;
    S4 nFTypeCount =0 ;
    S4 nLTypeCount =0;
    S4 nRet = COEXIT_SUCCESS;
    /*debug,12/11/07,S*/
    S4 floatCnt = -1;
    U4 tmpFloatCnt = 0;
    DOUBLE tmpFranction = 0;
    /*debug,12/11/07,E*/
	if (from == to) {
		return COEXIT_ERROR;
	}

	for (; i < to; i++)
	{
		switch( pszNumStr[i] ){
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			digit = pszNumStr[i] -'0';
			break;
		case '.':
			//TODO
			/*if too many decimal points in number*/
			/*number format should be checked before stepping into this function*/
			hasDot = TRUE;
			break;
		default:
			digit = 11;
			break;
		}
		if( digit >= 10 ){
			break;
		}
		if( hasDot == FALSE ){
			result_value= result_value*10. + digit;
		}else{
			/*debug,12/11/07,S*/
			floatCnt++;
			tmpFloatCnt = floatCnt;
			if(floatCnt > 0){
				tmpFranction = (DOUBLE)digit;
			}
			while(tmpFloatCnt){
				tmpFranction = tmpFranction/10;
				tmpFloatCnt--;
			}
			result_franction = result_franction + tmpFranction;
			/*debug,12/11/07,E*/
		}
	}
	result_value += result_franction;
	if( pszNumStr[i] == 'e' || pszNumStr[i] == 'E' ){
		i++;
		if( i < to ){
			if( pszNumStr[i] == '-' )
			{
				hasMinusSign = TRUE;
				i++;
			}else if( pszNumStr[i] == '+'){
				i++;
			}
			u4_Exponent = 0;
			for (; i < to; i++)
			{
				switch( pszNumStr[i] ){
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					digit = pszNumStr[i] -'0';
					break;
				default:
					digit = 11;
					break;
				}
				if( digit >= 10 ){
					break;
				}
				u4_Exponent = u4_Exponent*10 + digit;
			}
			while( u4_Exponent > 0 ){
				if( hasMinusSign ){
					result_value = result_value/10;
				}else{
					result_value = result_value*10;
				}
				u4_Exponent--;
			}
		}
	}
	for (; i < to; i++) {
		switch(pszNumStr[i]) {
		case 'f' : case 'F':
			nFTypeCount++;
			break;
		case 'l': case 'L':
			nLTypeCount++;
			break;
		default:
			nRet = COEXIT_ERROR;
			i = to;
			break;
		}
	}
	if( nRet == COEXIT_SUCCESS ){
		return ccValueSetFloatSuffix( nFTypeCount, nLTypeCount, result_value, pstValue );
	}else{
		pstValue->astType = (TYPE_DOUBLE);
		pstValue->unValue.dbVal = result_value;
	}
	return nRet;
}
static S4 ccValueTryHexFloatNumber( PSZ pszNumStr, S4 from, S4 to, PVALUEINFO pstValue )
{
	DOUBLE result_value= 0;
	DOUBLE result_franction=0;
	U4  u4_Exponent = 0;
	BOOL hasDot = FALSE;
	BOOL hasMinusSign = FALSE;
	S4 i= from;
	U4 digit=0;
    S4 nFTypeCount =0 ;
    S4 nLTypeCount =0;
    S4 nRet = COEXIT_SUCCESS;
	if (from == to) {
		return COEXIT_ERROR;
	}

	for (; i < to; i++)
	{
		switch( pszNumStr[i] ){
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			digit = pszNumStr[i] -'0';
			break;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
			digit = pszNumStr[i] - 'a' + 10;
			break;
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
			digit = pszNumStr[i] - 'A' + 10;
			break;
		case '.':
			hasDot = TRUE;
			break;
		default:
			digit = 20;
			break;
		}
		if( digit >= 16 ){
			break;
		}
		if( hasDot == FALSE ){
			result_value= result_value*16. + digit;
		}else{
			result_franction = result_franction + digit/16;
		}
	}
	result_value += result_franction;
	if( pszNumStr[i] == 'p' || pszNumStr[i] == 'P' ){
		i++;
		if( i < to ){
			if( pszNumStr[i] == '-' )
			{
				hasMinusSign = TRUE;
				i++;
			}else if( pszNumStr[i] == '+'){
				i++;
			}
			u4_Exponent = 0;
			for (; i < to; i++)
			{
				switch( pszNumStr[i] ){
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					digit = pszNumStr[i] -'0';
					break;
				default:
					digit = 11;
					break;
				}
				if( digit >= 10 ){
					break;
				}
				u4_Exponent = u4_Exponent*10 + digit;
			}
			while( u4_Exponent > 0 ){
				if( hasMinusSign ){
					result_value = result_value/2;
				}else{
					result_value = result_value*2;
				}
				u4_Exponent--;
			}
		}
	}
	for (; i < to; i++) {
		switch(pszNumStr[i]) {
		case 'f' : case 'F':
			nFTypeCount++;
			break;
		case 'l': case 'L':
			nLTypeCount++;
			break;
		default:
			nRet = COEXIT_ERROR;
			i = to;
			break;
		}
	}
	if( nRet == COEXIT_SUCCESS ){
		return ccValueSetFloatSuffix( nFTypeCount, nLTypeCount, result_value, pstValue );
	}else{
		pstValue->astType = (TYPE_DOUBLE);
		pstValue->unValue.dbVal = result_value;
	}
	return nRet;
}
static S4 ccValueGetFloatNumber(PSZ pszNumStr, PVALUEINFO pstValue )
{
    if (str_length(pszNumStr) > 1) {
    	if (pszNumStr[0] == '0') {
    		switch (pszNumStr[1]) {
    		case 'x':
    		case 'X':
    			return ccValueTryHexFloatNumber( &pszNumStr[2], 2, strlen( pszNumStr ), pstValue );
    		}
    	}
    }
	return ccValueTryFloatNumber( &pszNumStr[0], 0, strlen( pszNumStr ), pstValue );
}
static S4 ccValueGetNum( PSZ pszNum, PVALUEINFO pvalue )
{
	S4 nRet1;
	nRet1 = ccValueGetIntNumber( pszNum, pvalue );
	if( nRet1 == COEXIT_SUCCESS ){
		return COEXIT_SUCCESS;
	}
	nRet1 = ccValueGetFloatNumber( pszNum, pvalue );
	return nRet1;
}
#define COMPARE_BUFFER  /* for eclipse outline */
static BOOL ccValueIsValid(PVALUEINFO pst)
{
	if( pst == NULL ){
		return FALSE;
	}
	switch(  (pst->astType) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
	case TYPE_UNSIGNED_INT:
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
	case TYPE_UNSIGNED_LONG:
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
	case TYPE_UNSIGNED_LONG_LONG:
	case TYPE_FLOAT:
	case TYPE_DOUBLE:
	case TYPE_LONG_DOUBLE:
		return TRUE;
	default:
		break;
	}
	return FALSE;
}
static VOID ccValueConvertType( PVALUEINFO value, AST type ){
	switch( (type) ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueConvert2Int( value, type );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueConvert2UInt( value, type );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueConvert2Long( value, type );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueConvert2ULong( value, type );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueConvert2LongLong( value, type );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueConvert2ULongLong( value, type );
		break;
	case TYPE_FLOAT:
		ccValueConvert2Float( value, type );
		break;
	case TYPE_DOUBLE:
		ccValueConvert2Double( value, type );
		break;
	case TYPE_LONG_DOUBLE:
		ccValueConvert2LDouble( value, type );
		break;
	}
}
static S4 ccValueCompareSameType( PVALUEINFO pst1, PVALUEINFO pst2 )
{
	S4 result=0;
	switch( pst1->astType  ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		result =  ccValueCompareInt(pst1,pst2);
		break;
	case TYPE_UNSIGNED_INT:
		result = ccValueCompareUInt(pst1,pst2);
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		result = ccValueCompareLong(pst1,pst2);
		break;
	case TYPE_UNSIGNED_LONG:
		result = ccValueCompareUlong(pst1,pst2);
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		result = ccValueCompareLongLong(pst1,pst2);
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		result = ccValueCompareUlongLong( pst1, pst2 );
		break;
	case TYPE_FLOAT:
		result = ccValueCompareFloat( pst1, pst2 );
		break;
	case TYPE_DOUBLE:
		result = ccValueCompareDouble( pst1, pst2 );
		break;
	case TYPE_LONG_DOUBLE:
		result = ccValueCompareLDouble( pst1, pst2 );
		break;
	default:
		result = 0;
		break;
	}
	return result;
}
VOID CcValueInit(VOID){
	;
}
AST CcValueAddOrign( PSZ pszNum ){
	VALUEINFO value;
	AST astNew;

	if( pszNum == NULL ){
		return 0;
	}
	value.astType = 0;
	value.unValue.dbVal = 0;
	ccValueGetNum( pszNum, & value );
	astNew = stValueInfoAccess.addValue(&value);
	return astNew;
}
/*
* CcValueAddFloating
*   Put 'DOUBLE value by type 'astType into table-KIND_VALUEINFO, and
*   return the index
*   @astType   type
*   @value     value
*/
AST CcValueAddFloating( AST astType, DOUBLE value ){
	VALUEINFO st ;
	if( astType == TYPE_FLOAT
			|| astType == TYPE_DOUBLE
			|| astType == TYPE_LONG_DOUBLE ){
		st.astType = astType;
		st.unValue.dbVal = value;
		return stValueInfoAccess.addValue(&st);
	}
	return 0;
}
/*
* CcValueAddVarValue
*   Put 'VARVALUE value by type 'astType into table-KIND_VALUEINFO, and
*   return the index
*   @astType   type
*   @value     value
*/
AST CcValueAddVarValue( AST astType, VARVALUE value ){
	VALUEINFO st ;
	st.astType = astType;
	switch( astType )
	{
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		if( value.sign > 0 ){
			ccValueSetInt( &st, value.u8Remainder );
		}else{
			ccValueSetInt( &st, -value.u8Remainder );
		}
		break;
	case TYPE_UNSIGNED_INT:
		if( value.sign > 0 ){
			ccValueSetUInt( &st, value.u8Remainder );
		}else{
			ccValueSetUInt( &st, -value.u8Remainder );
		}
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		if( value.sign > 0 ){
			ccValueSetLong( &st, value.u8Remainder );
		}else{
			ccValueSetLong( &st, -value.u8Remainder );
		}
		break;
	case TYPE_UNSIGNED_LONG:
		if( value.sign > 0 ){
			ccValueSetULong( &st, value.u8Remainder );
		}else{
			ccValueSetULong( &st, -value.u8Remainder );
		}
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		if( value.sign > 0 ){
			ccValueSetLongLong( &st, value.u8Remainder );
		}else{
			ccValueSetLongLong( &st, -value.u8Remainder );
		}
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		if( value.sign > 0 ){
			ccValueSetULongLong( &st, value.u8Remainder );
		}else{
			ccValueSetULongLong( &st, -value.u8Remainder );
		}
		break;
	default:
		return 0;
	}
	return stValueInfoAccess.addValue(&st);
}

/*
* CcValueGetInteger
*   get the value in formation of VARVALUE
*   @astValue   value
*/
VARVALUE CcValueGetInteger( AST astValue ){
	VARVALUE stRet;
	VALUEINFO st;
	AST type = stValueInfoAccess.type.get( astValue );
	switch ((type)) {
	case TYPE_INT:
	case TYPE_SIGNED_INT: {
		S4 value;
		ccValueGetInt(astValue, &st);
		value = ccValueInt2S4(&st);
		if (value < 0) {
			stRet.sign = -1;
			stRet.u8Remainder = -value;
		} else {
			stRet.sign = 1;
			stRet.u8Remainder = value;
		}
		break;
	}
	case TYPE_UNSIGNED_INT: {
		U4 value;
		ccValueGetUInt(astValue, &st);
		value = ccValueUInt2U4(&st);
		stRet.sign = 1;
		stRet.u8Remainder = value;
		break;
	}
	case TYPE_LONG:
	case TYPE_SIGNED_LONG: {
		S8 value;
		ccValueGetLong(astValue, &st);
		value = ccValueLong2S8(&st);
		if (value < 0) {
			stRet.sign = -1;
			stRet.u8Remainder = -value;
		} else {
			stRet.sign = 1;
			stRet.u8Remainder = value;
		}
		break;
	}
	case TYPE_UNSIGNED_LONG: {
		U8 value;
		ccValueGetULong(astValue, &st);
		value = ccValueULong2U8(&st);
		stRet.sign = 1;
		stRet.u8Remainder = value;
		break;
	}
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG: {
		S8 value;
		ccValueGetLongLong(astValue, &st);
		value = ccValueLongLong2S8(&st);
		if (value < 0) {
			stRet.sign = -1;
			stRet.u8Remainder = -value;
		} else {
			stRet.sign = 1;
			stRet.u8Remainder = value;
		}
		break;
	}
	case TYPE_UNSIGNED_LONG_LONG: {
		U8 value;
		ccValueGetULongLong(astValue, &st);
		value = ccValueULongLong2U8(&st);
		stRet.sign = 1;
		stRet.u8Remainder = value;
		break;
	}
	case TYPE_FLOAT:
	case TYPE_DOUBLE:
	case TYPE_LONG_DOUBLE: {
		DOUBLE dbV = CcValueGetFloating(astValue);
		if (dbV < 0) {
			stRet.sign = -1;
			stRet.u8Remainder = (U8) (-dbV);
		} else {
			stRet.sign = 1;
			stRet.u8Remainder = (U8) dbV;
		}
		break;
	}
	default:
		stRet.sign = 1;
		stRet.u8Remainder = 0;
		break;
	}
	return stRet;
}
/*
* CcValueGetFloating
*   get the value in formation of double
*   @astValue   value
*/
DOUBLE CcValueGetFloating( AST astValue ){
	VARVALUE stRet;
	VALUEINFO st;
	DOUBLE dbV;
	AST type = stValueInfoAccess.type.get( astValue );
	switch ((type)) {
	case TYPE_INT:
	case TYPE_SIGNED_INT:
	case TYPE_UNSIGNED_INT:
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
	case TYPE_UNSIGNED_LONG:
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
	case TYPE_UNSIGNED_LONG_LONG:
		stRet = CcValueGetInteger( astValue );
		dbV = (DOUBLE)stRet.u8Remainder;
		if( stRet.sign < 0 ){
			dbV = -dbV;
		}
		break;
	case TYPE_FLOAT:{
		ccValueGetFloat(astValue, &st);
		dbV = (DOUBLE) ccValueFloat2Float(&st);
		break;
	}
	case TYPE_DOUBLE:
		ccValueGetDouble( astValue ,& st );
		dbV = ccValueDouble2Double( &st );
		break;
	case TYPE_LONG_DOUBLE:
		ccValueGetLDouble( astValue ,& st );
		dbV = ccValueLDouble2LDouble( &st );
		break;
	default:
		dbV = 0.;
		break;
	}
	return dbV;
}

/*
 * CcValueCompareBuf
 *   comparator in formation of PVALUEINFO
 *   @buf1   value1
 *   @buf2   value2
 */
static S4 ccValueCompareBuf( PVALUEINFO buf1, PVALUEINFO buf2)
{
    PVALUEINFO pst1, pst2;
    VALUEINFO value1, value2;
//    AST astType;
    if( buf1 == NULL && buf2 == NULL ){
    	return 0;
    }
    if( buf1 == NULL ){
    	return -1;
    }else if( buf2 == NULL ){
    	return 1;
    }
    pst1 = (PVALUEINFO)buf1;
    pst2 = (PVALUEINFO)buf2;
	value1 = *pst1;
	value2 = *pst2;
    if( !ccValueIsValid( &value1 ) ){
    	return -1;
    }else if( !ccValueIsValid( &value2 ) ){
    	return 1;
    }
	if( value1.astType != value2.astType  ){
		/*astType =*/ CcTypeGetArithConversion( value1.astType, value2.astType );
		ccValueConvertType( &value1, value1.astType );
		ccValueConvertType( &value1, value2.astType );
	}
	return ccValueCompareSameType(&value1, &value2);
}
/*
* ccValueGetDataBuf
*   get the value in formation of VARVALUE
*   @index   KIND_VALUEINFO-object
*   @buf     output
*/
static VOID ccValueGetDataBuf( AST index, PVALUEINFO buf )
{
	if( buf == NULL || index == 0 ){
		return;
	}

	buf->astType = stValueInfoAccess.type.get( index );
	if( buf->astType == 0 ){
		return ;
	}
	memset( & buf->unValue, 0, sizeof( buf->unValue ) );
	switch( ( buf->astType )){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueGetInt( index, buf );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueGetUInt( index, buf );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueGetLong( index, buf );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueGetULong( index, buf );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueGetLongLong( index, buf );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueGetULongLong( index, buf );
		break;
	case TYPE_FLOAT:
		ccValueGetFloat( index, buf );
		break;
	case TYPE_DOUBLE:
		ccValueGetDouble( index, buf );
		break;
	case TYPE_LONG_DOUBLE:
		ccValueGetLDouble( index, buf );
		break;
	default:
		break;
	}
}
/*
* CcValueCompareBuf
*   comparator of two KIND_VALUEINFO-objects
*   @idx1   value1
*   @idx2   value2
*/
S4 CcValueCompareIdx( AST idx1, AST idx2 )
{
	VALUEINFO st1, st2;

   if( idx1 == idx2 )
   {
   	return 0;
   }
   ccValueGetDataBuf( idx1, (PVALUEINFO)&st1 );
   ccValueGetDataBuf( idx2, (PVALUEINFO)&st2 );
   return ccValueCompareBuf((PVALUEINFO)&st1, (PVALUEINFO)&st2 );
}
/*
 * CcValueCompareForTree
 *   comparator for red black tree
 *   @pst1   value1
 *   @pst2   value2
 */
S4 CcValueCompareForTree( PVALUEINFO pst1, PVALUEINFO pst2 )
{
	VALUEINFO value1, value2;
	if( pst1 == NULL && pst2 == NULL )
	{
		return 0;
	}
	if( pst1 == NULL )
	{
		return -1;
	}
	if( pst2 == NULL )
	{
		return 1;
	}
	if( pst1->astType < pst2->astType )
	{
		return -1;
	}
	if( pst1->astType > pst2->astType )
	{
		return 1;
	}
	value1 = *pst1;
	value2 = *pst2;
	return ccValueCompareSameType( &value1, &value2 );
}
/*
 * CcValueGetMaxValue
 *   get maximum value of type(astType)
 *   @astType   KIND_TYPEDEFINFO-object
 */
AST CcValueGetMaxValue( AST astType ){
	VALUEINFO value;
	U4 size = stTypeInfoAccess.size.get( astType );
	U8 u8V;
	value.astType = astType;
	if( CcTypeIsSigned( astType )){
		u8V = 1ULL << ( size*CHARBIT - 1 );
		u8V--;
	}else{
		if( size < 8 ){
			u8V = 1ULL << ( size*CHARBIT );
			u8V--;
		}else{
			u8V = 0;
			u8V = ~u8V;
		}
	}
	switch( astType ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueSetInt(&value, u8V );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueSetUInt(&value, u8V );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueSetLong(&value, u8V );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueSetULong(&value, u8V );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueSetLongLong(&value, u8V );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueSetULongLong(&value, u8V );
		break;
	default:
		return 0;
	}
	return stValueInfoAccess.addValue(& value );
}
/*
 * CcValueGetMinValue
 *   get minimum value of type(astType)
 *   @astType   KIND_TYPEDEFINFO-object
 */
AST CcValueGetMinValue( AST astType ){
	VALUEINFO value;
	U4 size = stTypeInfoAccess.size.get( astType );
	U8 u8V;
	value.astType = astType;
	if( CcTypeIsSigned( astType )){
		u8V = 1ULL << ( size*CHARBIT - 1 );
	}else{
		u8V = 0;
	}
	switch( astType ){
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueSetInt(&value, u8V );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueSetUInt(&value, u8V );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueSetLong(&value, u8V );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueSetULong(&value, u8V );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueSetLongLong(&value, u8V );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueSetULongLong(&value, u8V );
		break;
	default:
		return 0;
	}
	return stValueInfoAccess.addValue(& value );
}
/*
 * CcValueGetOne
 *   get 0-value in type(astType)
 *   @astType   KIND_TYPEDEFINFO-object
 */
AST CcValueGetOne( AST astType ){
	VALUEINFO stValue;
	stValue.astType = astType;
	switch( astType )
	{
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueSetInt( &stValue, 1 );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueSetUInt( &stValue, 1 );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueSetLong( &stValue, 1 );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueSetULong( &stValue, 1 );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueSetLongLong( &stValue, 1 );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueSetULongLong( &stValue, 1 );
		break;
	case TYPE_FLOAT:
		ccValueSetFloat( &stValue, 1 );
		break;
	case TYPE_DOUBLE:
		ccValueSetDouble( &stValue, 1 );
		break;
	case TYPE_LONG_DOUBLE:
		ccValueSetLDouble( &stValue, 1 );
		break;
	default:
		return 0;
	}
	return stValueInfoAccess.addValue(&stValue);
}
/*
 * CcValueGetZero
 *   get 0-value in type(astType)
 *   @astType   KIND_TYPEDEFINFO-object
 */
AST CcValueGetZero( AST astType ){
	VALUEINFO st ;
	st.astType = astType;
	switch( astType )
	{
	case TYPE_INT:
	case TYPE_SIGNED_INT:
		ccValueSetInt( &st, 0 );
		break;
	case TYPE_UNSIGNED_INT:
		ccValueSetUInt( &st, 0 );
		break;
	case TYPE_LONG:
	case TYPE_SIGNED_LONG:
		ccValueSetLong( &st, 0 );
		break;
	case TYPE_UNSIGNED_LONG:
		ccValueSetULong( &st, 0 );
		break;
	case TYPE_LONG_LONG:
	case TYPE_SIGNED_LONG_LONG:
		ccValueSetLongLong( &st, 0 );
		break;
	case TYPE_UNSIGNED_LONG_LONG:
		ccValueSetULongLong( &st, 0 );
		break;
	case TYPE_FLOAT:
		ccValueSetFloat( &st, 0 );
		break;
	case TYPE_DOUBLE:
		ccValueSetDouble( &st, 0 );
		break;
	case TYPE_LONG_DOUBLE:
		ccValueSetLDouble( &st, 0 );
		break;
	default:
		return 0;
	}
	return stValueInfoAccess.addValue(&st);
}
/*
 * CcValueIsPositive
 *   whether the value is positive.
 *   @astValue   KIND_VALUEINFO-object
 */
BOOL CcValueIsPositive( AST astValue ){
	AST astType = stValueInfoAccess.type.get( astValue );
	if( CcTypeIsInteger( astType )){
		VARVALUE value = CcValueGetInteger( astValue );
		return value.sign > 0 ;
	}else{
		DOUBLE value = CcValueGetFloating( astValue );
		return value > 0.;
	}
}
/*
 * CcValueIsNegative
 *   whether the value is negative.
 *   @astValue   KIND_VALUEINFO-object
 */
BOOL CcValueIsNegative( AST astValue ){
	AST astType = stValueInfoAccess.type.get( astValue );
	if( CcTypeIsInteger( astType )){
		VARVALUE value = CcValueGetInteger( astValue );
		return value.sign < 0 ;
	}else{
		DOUBLE value = CcValueGetFloating( astValue );
		return value < 0.;
	}
}
/*
 * CcValueIsZero
 *   whether the value is 0.
 *   @astIndex   KIND_VALUEINFO-object
 */
BOOL CcValueIsZero(AST astIndex){
	AST astType = stValueInfoAccess.type.get( astIndex );
	if( CcTypeIsInteger( astType )){
		VARVALUE value = CcValueGetInteger( astIndex );
		return value.u8Remainder == 0;
	}else{
		DOUBLE value = CcValueGetFloating( astIndex );
		return value == 0.;
	}
}
/* end of file */
